﻿Imports System.Data
Imports System.Data.OleDb

Public Class DAL_Thi

    Public conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\10650_000\Desktop\ltudql1-doan\Database\Database.mdb"


    Dim i As Integer

    Public Function TaoCauHoiChoDe1(ByVal TXTMABODE As String) As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String = " SELECT CAUHOI.MaCauHoi, CAUHOI.NoiDung, CAUHOI.DAA, CAUHOI.DAB, CAUHOI.DAC, CAUHOI.DAD, CAUHOI.DADung, CAUHOICHOBODE.MaBoDe FROM CAUHOI INNER JOIN CAUHOICHOBODE ON CAUHOI.MaCauHoi = CAUHOICHOBODE.MaCauHoi WHERE (CAUHOICHOBODE.MaBoDe) = '" & TXTMABODE & "'  order by   CAUHOI.NoiDung desc "

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

    Public Function TaoCauHoiChoDe2(ByVal TXTMABODE As String) As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String = " SELECT CAUHOI.MaCauHoi, CAUHOI.NoiDung, CAUHOI.DAA, CAUHOI.DAB, CAUHOI.DAC, CAUHOI.DAD, CAUHOI.DADung, CAUHOICHOBODE.MaBoDe FROM CAUHOI INNER JOIN CAUHOICHOBODE ON CAUHOI.MaCauHoi = CAUHOICHOBODE.MaCauHoi WHERE (CAUHOICHOBODE.MaBoDe) = '" & TXTMABODE & "'  order by   CAUHOI.NoiDung asc "

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

    Public Function TaoCauHoiChoDe3(ByVal TXTMABODE As String) As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String = " SELECT CAUHOI.MaCauHoi, CAUHOI.NoiDung, CAUHOI.DAA, CAUHOI.DAB, CAUHOI.DAC, CAUHOI.DAD, CAUHOI.DADung, CAUHOICHOBODE.MaBoDe FROM CAUHOI INNER JOIN CAUHOICHOBODE ON CAUHOI.MaCauHoi = CAUHOICHOBODE.MaCauHoi WHERE (CAUHOICHOBODE.MaBoDe) = '" & TXTMABODE & "'  order by   CAUHOI.MaCauHoi desc "

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

    Public Function TaoCauHoiChoDe4(ByVal TXTMABODE As String) As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String = " SELECT CAUHOI.MaCauHoi, CAUHOI.NoiDung, CAUHOI.DAA, CAUHOI.DAB, CAUHOI.DAC, CAUHOI.DAD, CAUHOI.DADung, CAUHOICHOBODE.MaBoDe FROM CAUHOI INNER JOIN CAUHOICHOBODE ON CAUHOI.MaCauHoi = CAUHOICHOBODE.MaCauHoi WHERE (CAUHOICHOBODE.MaBoDe) = '" & TXTMABODE & "'  order by   CAUHOI.MaCauHoi asc "

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

    ' Public Sub ThemDuLieuChoBangDapAn(ByVal masv As String, ByVal stt As String, ByVal Chon As String, ByVal dadung As String, _
    ' ByVal noidung As String, ByVal daa As String, ByVal dab As String, ByVal dac As String, ByVal dad As String)
    ' Dim StrSQL As String
    '  StrSQL = "Insert into dapantam (masv,stt,noidung,daa,dab,dac,dad,dadung,Chon) values (@masv,@stt,@noidung,@daa,@dab,@dac,@dad,@dadung,@Chon)"
    '  Dim con As New OleDbConnection(conn)
    ' Dim cmd As New OleDbCommand(StrSQL, con)
    '  With cmd.Parameters
    '    .Add("@maSV", OleDbType.VarChar).Value = masv
    '    .Add("@stt", OleDbType.VarChar).Value = stt
    '    .Add("@noidung", OleDbType.VarChar).Value = noidung
    '   .Add("@daa", OleDbType.VarChar).Value = daa
    '  .Add("@dab", OleDbType.VarChar).Value = dab
    '   .Add("@dac", OleDbType.VarChar).Value = dac
    '  .Add("@dad", OleDbType.VarChar).Value = dad
    '  .Add("@dadung", OleDbType.VarChar).Value = dadung
    '  .Add("@chon", OleDbType.VarChar).Value = Chon
    ' End With
    ' con.Open()
    ' cmd.ExecuteNonQuery()
    ' con.Close()
    ' End Sub

    Public Function LoadDuLieuSinhVienVaDeThiKhiDangNhapThanhCong(ByVal masv As String) As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String

        StrSQL = "Select * from SINHVIEN_THI where masv = '" & masv & "'"

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

    Public Sub LuuBaiLamKhiAnNutHoanThanh(ByVal Mabode As String, ByVal made As String, ByVal masv As String, ByVal tensv As String, _
    ByVal ngaythi As String, ByVal diemthi As String)

        Dim StrSQL As String

        StrSQL = "Insert into CTSVTHI (Mabode,made,masv,tensv,ngaythi,diemthi) values(@Mabode,@made,@masv,@tensv,@ngaythi,@diemthi)"

        Dim con As New OleDbConnection(conn)

        Dim cmd As New OleDbCommand(StrSQL, con)

        With cmd.Parameters

            .Add("@Mabode", OleDbType.VarChar).Value = Mabode

            .Add("@Made", OleDbType.VarChar).Value = made

            .Add("@masv", OleDbType.VarChar).Value = masv

            .Add("@tensv", OleDbType.VarChar).Value = tensv

            .Add("@ngaythi", OleDbType.VarChar).Value = ngaythi

            .Add("@diemthi", OleDbType.VarChar).Value = diemthi

        End With

        con.Open()

        cmd.ExecuteNonQuery()

        con.Close()

    End Sub

    Public Function LoadDuLieuLuuTamKhiCoSuCo(ByVal masv As String) As DataTable

        Dim dt As New DataTable

        Dim StrSQL As String

        StrSQL = "Select * from LUU_TAM where masv = '" & masv & "' order by cauhoi asc"

        Dim con As New OleDbConnection(conn)

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

    Public Sub LuuKetQuaTamTruocKhiGapSuCo(ByVal macauhoi As String, ByVal noidung As String, ByVal daa As String, _
    ByVal dab As String, ByVal dac As String, ByVal dad As String, ByVal dadung As String, _
   ByVal mabode As String, ByVal cauhoi As String, ByVal chon As String, ByVal phut As String, ByVal madethi As String, ByVal masv As String)

        Dim StrSQL As String

        StrSQL = "Insert into LUU_TAM (macauhoi,noidung,daa,dab,dac,dad,dadung,mabode,cauhoi,chon,phut,madethi,masv) values(@macauhoi,@noidung,@daa,@dab,@dac,@dad,@dadung,@mabode,@cauhoi,@chon,@phut,@madethi,@masv)"

        Dim con As New OleDbConnection(conn)

        Dim cmd As New OleDbCommand(StrSQL, con)

        With cmd.Parameters

            .Add("@macauhoi", OleDbType.VarChar).Value = macauhoi

            .Add("@noidung", OleDbType.VarChar).Value = noidung

            .Add("@daa", OleDbType.VarChar).Value = daa

            .Add("@dab", OleDbType.VarChar).Value = dab

            .Add("@dac", OleDbType.VarChar).Value = dac

            .Add("@dad", OleDbType.VarChar).Value = dad

            .Add("@dadung", OleDbType.VarChar).Value = dadung

            .Add("@mabode", OleDbType.VarChar).Value = mabode

            .Add("@cauhoi", OleDbType.VarChar).Value = cauhoi

            .Add("@chon", OleDbType.VarChar).Value = chon

            .Add("phut", OleDbType.VarChar).Value = phut

            .Add("Madethi", OleDbType.VarChar).Value = madethi

            .Add("@masv", OleDbType.VarChar).Value = masv


        End With

        con.Open()

        cmd.ExecuteNonQuery()

        con.Close()
    End Sub

    Public Function XoaDuLieuLuuTamTruocKhiLuu(ByVal masv As String) As DataTable

        Dim dt As New DataTable

        Dim con As New OleDbConnection(conn)

        Dim StrSQL As String

        StrSQL = "Delete * from LUU_TAM where masv = '" & masv & "'"

        Dim da As New OleDbDataAdapter(StrSQL, con)

        da.Fill(dt)

        Return dt

    End Function

End Class


